using Beaker;
using Beaker.Injection;
using Beaker.Specs;
using OpenCube.Nbt.Mapping;
using OpenCube.Nbt.Mapping.Converters;
using OpenCube.Nbt.Specs.Builders;

namespace OpenCube.Model.Specs.Builders
{
	internal class NbtMapperFactoryBuilder
		: Builder<NbtMapperFactory>
	{
		private Maybe<IBuildInConverterFactory> _converterFactory;
		private Maybe<IQueryContainer> _queryContainer;

		public NbtMapperFactoryBuilder WithQueryContainer(IQueryContainer queryContainer)
		{
			_queryContainer = new Maybe<IQueryContainer>(queryContainer);
			return this;
		}

		public NbtMapperFactoryBuilder WithConverterFactory(IBuildInConverterFactory converterFactory)
		{
			_converterFactory = new Maybe<IBuildInConverterFactory>(converterFactory);
			return this;
		}

		public override NbtMapperFactory Build()
		{
			IQueryContainer queryContainer = _queryContainer.GetValueOrDefault(
				() => new QueryContainerStub());
			IBuildInConverterFactory converterFactory = _converterFactory.GetValueOrDefault(
				new BuildInConverterFactory(queryContainer));

			return new NbtMapperFactory(converterFactory, queryContainer);
		}
	}
}